package com.acwing.partition4;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/22 9:32
 */
public class AC321棋盘分割 {

    private static final int INF = 0x3f3f3f3f;

    private static double[][][][][] memo;
    private static int[][] prefix;
    private static int n;
    private static double x;

    private static double memoization(int x1, int y1, int x2, int y2, int k) {
        double val = memo[x1][x2][y1][y2][k];
        if (val > 0) return val;
        if (k == 1) return memo[x1][x2][y1][y2][k] = cal(x1, y1, x2, y2);
        val = INF;
        for (int i = x1; i < x2; i++) {
            val = Math.min(val, memoization(x1, y1, i, y2, k - 1) + cal(i + 1, y1, x2, y2));
            val = Math.min(val, memoization(i + 1, y1, x2, y2, k - 1) + cal(x1, y1, i, y2));
        }
        for (int j = y1; j < y2; j++) {
            val = Math.min(val, memoization(x1, y1, x2, j, k - 1) + cal(x1, j + 1, x2, y2));
            val = Math.min(val, memoization(x1, j + 1, x2, y2, k - 1) + cal(x1, y1, x2, j));
        }
        if (memo[x1][x2][y1][y2][k] == 0) memo[x1][x2][y1][y2][k] = val;
        else memo[x1][x2][y1][y2][k] = Math.min(memo[x1][x2][y1][y2][k], val);
        return memo[x1][x2][y1][y2][k];
    }

    private static double cal(int x1, int y1, int x2, int y2) {
        double sum = prefix[x2][y2] - prefix[x2][y1 - 1] - prefix[x1 - 1][y2] + prefix[x1 - 1][y1 - 1] - x;
        return sum * sum / n;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split("\\s+");
        n = Integer.parseInt(s[0]);
        prefix = new int[10][10];
        memo = new double[9][9][9][9][n + 1];
        for (int i = 1; i < 9; i++) {
            s = reader.readLine().split("\\s+");
            for (int j = 1; j < 9; j++) prefix[i][j] = Integer.parseInt(s[j - 1]);
        }
        //计算矩阵前缀和
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                prefix[i][j] += prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1];
            }
        }
        x = prefix[9][9] / (double) n;
        writer.write(String.format("%.3f\n", Math.sqrt(memoization(1, 1, 8, 8, n))));
        writer.flush();
    }
}
